<template>

  <div class="app-container">

    <div style="margin-bottom: 10px; font-size: 15px">
      选择：{{ baseMap.hosname }}/{{ depname }}/{{ workDate }}
    </div>

    <el-container style="height: 100%">

      <el-aside width="200px" style="border: 1px solid silver">
        <!--部门-->

        <el-tree
          :data="data"
          :props="defaultProps"
          :default-expand-all="true"
          @node-click="handleNodeClick"
        />

      </el-aside
      >

      <el-main style="padding: 00020px">

        <el-row style="width: 100%">
          <!--排班日期分页-->
          <el-tag
            v-for="(item, index) in bookingScheduleList"
            :key="item.id"
            :type="index == activeIndex ? '' : 'info'"
            style="
              height: 60px;
              margin-right: 5px;
              margin-right: 15px;
              cursor: pointer;
            "
            @click="selectDate(item.workDate, index)"
          >
            {{ item.workDate }}{{ item.dayOfWeek }}<br>
            {{ item.availableNumber }}/{{
              item.reservedNumber
            }}

          </el-tag
          >

          <!--分页-->

          <el-pagination
            :current-page="pageNum"
            :total="total"
            :page-size="pageSize"
            class="pagination"
            layout="prev,pager,next"
            @current-change="getPage"
          />

        </el-row
        >

        <el-row style="margin-top: 20px">
          <!--排班日期对应的排班医生-->
          <!--排班日期对应的排班医生-->

          <el-table
            v-loading="listLoading"
            :data="scheduleList"
            border
            fit
            highlight-current-row
          >

            <el-table-column
              label="序号"
              width="60"
              align="center"
            >
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template
              >
            </el-table-column
            >

            <el-table-column label="职称" width="150">
              <template slot-scope="scope">
                {{ scope.row.title }}|{{ scope.row.docname }}
              </template>
            </el-table-column>
            <el-table-column
              label="号源时间"
              width="80">

              <template slot-scope="scope">
                {{ scope.row.workTime == 0 ? '上午' : '下午' }}
              </template
              >

            </el-table-column
            >

            <el-table-column
              prop="reservedNumber"
              label="可预约数"
              width="80"
            />

            <el-table-column
              prop="availableNumber"
              label="剩余预约数"
              width="100"
            />

            <el-table-column
              prop="amount"
              label="挂号费(元)"
              width="90"
            />

            <el-table-column
              prop="skill"
              label="擅长技能"
            />

          </el-table
          >

        </el-row
        >

      </el-main
      >

    </el-container
    >

  </div>
</template>
<script>
import hospApi from '@/api/hospital'

export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: 'children',
        label: 'depname'
      },
      hoscode: null,
      activeIndex: 0,
      depcode: null,
      depname: null,
      workDate: null,
      bookingScheduleList: [],
      baseMap: {},
      pageNum: 1, // 当前页
      pageSize: 7, // 每页个数
      total: 0, // 总页码
      scheduleList: [],
      listLoading: true
    }
  },
  created() {
    this.hoscode = this.$route.params.hoscode
    this.fetchData()
  },
  methods: {
    // 点击科室列表
    handleNodeClick(data) {
      if (data.children != null) return
      this.depcode = data.depcode
      this.depname = data.depname
      this.getPage()
    },
    // 查询排版时间
    fetchData() {
      hospApi.getDeptByHoscode(this.hoscode).then((response) => {
        this.data = response.data
        // 默认选中第一个
        if (this.data.length > 0) {
          this.depcode = this.data[0].children[0].depcode
          this.depname = this.data[0].children[0].depname
          this.getPage()
        }
      })
    },
    // 点击排版时间
    selectDate(workDate, index) {
      this.workDate = workDate
      this.activeIndex = index
      this.getDetailSchedule()
    },
    // 换页
    getPage(page = 1) {
      this.pageNum = page
      this.workDate = null
      this.activeIndex = 0
      this.getScheduleRule()
    },
    // 排版规则
    getScheduleRule() {
      hospApi
        .getScheduleRule(
          this.pageNum,
          this.pageSize,
          this.hoscode,
          this.depcode
        )
        .then((response) => {
          this.bookingScheduleList = response.data.bookingScheduleRuleList
          this.baseMap = response.data.baseMap
          this.total = response.data.total
          console.log('total=>' + this.total)
          // 分页后workDate=null，默认选中第一个
          if (this.workDate == null) {
            this.workDate = this.bookingScheduleList[0].workDate
          }
          this.getDetailSchedule()
        })
    },
    // 排班详情
    getDetailSchedule() {
      hospApi
        .getDetailSchedule(this.hoscode, this.depcode, this.workDate)
        .then((response) => {
          this.scheduleList = response.data
          this.listLoading = false
        })
    }
  }
}
</script>

<style>
.el-tree-node.is-current > .el-tree-node__content {
  background-color: #409eff !important;
  color: white;
}

.el-checkbox__input.is-checked + .el-checkbox__label {
  color: black;
}
</style>

